﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Framework;
using OLTS.DAL;
using OLTS.MODEL;
namespace OLTS.DATA_SERVICE
{
    public class Site_Service
    {
        private OTS_SITE _objApp;
        private int _siteId;
        public Site_Service(OTS_SITE objApp)
        {
            _objApp = objApp;
        }

        public Site_Service()
        {

        }
        public Site_Service(int siteId)
        {
            _siteId = siteId;
        }
        public List<OTS_SITE> GetAll()
        {
            using (var ctx = new Entities())
            {
                var res = new List<OTS_SITE>();
                res = ctx.OTS_SITE.Where(x => x.STATUS == true).ToList();
                return res;
            }
        }

        public OTS_SITE GetByIdSite()
        {
            using (var ctx = new Entities())
            {
                var res = ctx.OTS_SITE.Where(x => x.ID == _siteId && x.STATUS == true).FirstOrDefault();
                return res;
            }
        }

        public void Add()
        {
            var ctx = new Entities();
            _objApp.CREATED = DateTime.Now; 
            ctx.OTS_SITE.AddObject(_objApp);
            ctx.SaveChanges();
        }
        public void Edit()
        {
            var ctx = new Entities();
            var obj = ctx.OTS_SITE.Where(x => x.ID == _objApp.ID).FirstOrDefault();
            if (obj != null)
            {
                obj.NAME = _objApp.NAME;
                obj.TIMESHEET_FORMAT = _objApp.TIMESHEET_FORMAT;
                obj.CREATED = DateTime.Now;
            }

            ctx.SaveChanges();
        }
        public void Delete()
        {
            var ctx = new Entities();
            var obj = ctx.OTS_SITE.Where(x => x.ID == _objApp.ID).FirstOrDefault();
            if (obj != null)
            {
                obj.STATUS = false;
                obj.CREATED = DateTime.Now;
            }
            //ctx.OTS_SITE.DeleteObject(obj);
            ctx.SaveChanges();
        }
    }
}
